package com.fatgirl.baseUI.visual
{
	import flash.display.DisplayObject;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import com.fatgirl.baseUI.IRadioButton;
	import com.fatgirl.baseUI.IRadioButtonGroup;
	
	
	/**
	 * 单选按钮 
	 * 单选按钮被选中后 其目标对象targetDisObj的visible为true，若被取消选择targetDisObj的visible 为false
	 * 针对可视化编程
	 * @author iceman
	 * 
	 */
	public class VRadioButton extends VLabelButton implements IRadioButton
	{
		private var m_IRadioButtonGroup:IRadioButtonGroup;
		private var m_groupName:String;
		private var m_value:Object;
		private var m_disObj:DisplayObject;
		public function VRadioButton()
		{
			this.addEventListener(MouseEvent.CLICK,clickHandler);
		}
		
		public function get group():IRadioButtonGroup
		{
			return m_IRadioButtonGroup;
		}
		
		public function set group(_IRadioButtonGroup:IRadioButtonGroup):void
		{
			m_IRadioButtonGroup = _IRadioButtonGroup;
			if(m_IRadioButtonGroup) m_groupName = m_IRadioButtonGroup.name;
		}
		
		public function get groupName():String
		{
			return m_groupName;
		}
		
		public function get value():Object
		{
			return m_value;
		}
		
		public function set value(_value:Object):void
		{
			m_value = _value;
		}
		public override function set selected(_b:Boolean):void
		{
			super.selected = _b;
			if(selected)
			{
				this.removeEventListener(MouseEvent.CLICK,clickHandler);
				if(m_disObj)m_disObj.visible = true;
			}
			else
			{
				this.addEventListener(MouseEvent.CLICK,clickHandler);
				if(m_disObj)m_disObj.visible = false;
			}
		}
		public function get targetDisObj():DisplayObject
		{
			return m_disObj;
		}
		public function set targetDisObj(_disObj:DisplayObject):void
		{
			m_disObj = _disObj;
			if(!m_disObj) return;
			if(selected) m_disObj.visible = true;
			else m_disObj.visible = false;
		}
		private function clickHandler(e:MouseEvent):void
		{
			this.selected = true;
		}
	}
}